﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
public abstract class EventPanel : BasePanel
{
    protected int id;
    public Text title;
    public Text content;
    public Image image;
    //public CanvasGroup hand1, hand2, hand3;
    //public Text optionText1, optionText2, optionText3;
    protected int optionNum;
    protected string[] optionTypes;
    protected string[] optionNames;
    protected string[] optionValues;
    protected bool activated;
    protected Vector3 MousePos;
    protected string imagePath;
    public void setEvent(EventInfo e)
    {
        id = e.id;
        title.text = e.title;
        content.text = e.content;
        optionNum = e.optionNum;
        optionTypes = e.optionType;
        optionValues = e.operationValue;
        optionNames = e.optionName;
        imagePath = e.imagePath;
    }

    public void gotoOption(int order)
    {
        int values;
        //Destroy(gameObject);
        switch (optionTypes[order])
        {
            case "Event"://调转事件
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                EventManager.Instance.OnTriggerEvent(values);
                break;
            case "Resource"://增减资源
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                if (values > 0)
                {
                    ResourceManager.Instance.GainResource(ResourceType.Money, values);
                    MessageController.Instance.SendMsg("增加金钱：" + values);
                }
                else
                {
                    float current =ResourceManager.Instance.GetCurrResourceCount(ResourceType.Money);
                    if(current+ values<=0)
                    {
                        ResourceManager.Instance.TryConsumeResource(ResourceType.Money, current);
                    }
                    else
                    {
                        ResourceManager.Instance.TryConsumeResource(ResourceType.Money, -values);
                    }
                    MessageController.Instance.SendMsg("减少金钱：" + values);
                }
                //TODO 增减资源
                break;
            case "Building"://对当前方块修改
                UIManager.Instance.PopPanel();
                //TODO 根据id修改当前方块
                break;
            case "Buff"://添加buff
                UIManager.Instance.PopPanel();
                //TODO 根据id添加Buff
                break;
            case "Attack"://增减攻击力
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                if (values > 0)
                {
                    MessageController.Instance.SendMsg("增加攻击力：" + values);
                }
                else
                {
                    MessageController.Instance.SendMsg("减少攻击力：" + values);
                }
                //增减攻击力
                GameObject.Find("Player").GetComponent<BattleObject>().SetBuff(new BuffInfo((int)ConstOfBuff.BuffType.RepeatableAttackIncrease, values, -1));
                break;
            case "AttackRange"://增减攻击范围
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                if (values > 0)
                {
                    MessageController.Instance.SendMsg("增加攻击范围：" + values);
                }
                else
                {
                    MessageController.Instance.SendMsg("减少攻击范围：" + values);
                }
                //TODO 增减攻击范围
                break;
            case "AttackSpeed"://增减攻击速度
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                if (values > 0)
                {
                    MessageController.Instance.SendMsg("增加攻击速度：" + values);
                }
                else
                {
                    MessageController.Instance.SendMsg("减少攻击速度：" + values);
                }
                //TODO 增减攻击速度
                break;
            case "Terrain"://修改地形
                UIManager.Instance.PopPanel();
                //TODO 修改地形
                break;
            case "HP"://修改HP
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                if(values>0)
                {
                    MessageController.Instance.SendMsg("恢复生命值：" + values);
                }
                else
                {
                    MessageController.Instance.SendMsg("损失生命值：" + values);
                }
                Player.Instance.GetComponent<HitPoint>().changeHP(values);
                break;
            case "MaxHP"://修改MaxHP
                int.TryParse(optionValues[order], out values);
                UIManager.Instance.PopPanel();
                if (values > 0)
                {
                    MessageController.Instance.SendMsg("增加最大生命值：" + values);
                }
                else
                {
                    MessageController.Instance.SendMsg("损失最大生命值：" + values);
                }
                GameObject.Find("Player").GetComponent<BattleObject>().changeMaxHP(values);
                break;
            default:
                break;
        }
    }
}

